{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Advanced Topic: Using External C++ Functions\n", "\n", "This is based on the relevant portion of the CmdStan documentation [here](https://mc-stan.org/docs/cmdstan-guide/using-external-cpp-code.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Consider the following Stan model, based on the bernoulli example." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "import os\n", "try:\n", " os.remove('bernoulli_external')\n", "except:\n", " pass" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "functions {\n", " real make_odds(real theta);\n", "}\n", "data {\n", " int N;\n", " array[N] int y;\n", "}\n", "parameters {\n", " real theta;\n", "}\n", "model {\n", " theta ~ beta(1, 1); // uniform prior on interval 0, 1\n", " y ~ bernoulli(theta);\n", "}\n", "generated quantities {\n", " real odds;\n", " odds = make_odds(theta);\n", "} \n", "\n" ] } ], "source": [ "with open('bernoulli_external.stan', 'r') as f:\n", " stan_code = f.read()\n", "print(stan_code)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see, it features a function declaration for `make_odds`, but no definition. If we try to compile this, we will get an error. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [ "raises-exception" ] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "12:25:18 - cmdstanpy - INFO - compiling stan file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan to exe file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n" ] }, { "ename": "ValueError", "evalue": "Failed to compile Stan model '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan'. Console:\n\n--- Translating Stan model to C++ code ---\nbin/stanc --filename-in-msg=bernoulli_external.stan --o=/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan\nSemantic error in 'bernoulli_external.stan', line 2, column 7 to column 16:\n -------------------------------------------------\n 1: functions {\n 2: real make_odds(real theta);\n ^\n 3: }\n 4: data {\n -------------------------------------------------\n\nFunction 'make_odds' is declared without specifying a definition.\nmake: *** [make/program:66: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp] Error 1\n\nCommand ['make', 'STANCFLAGS+=--filename-in-msg=bernoulli_external.stan', '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external']\n\texited with code '2' No such file or directory\n", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[34;01mcmdstanpy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m CmdStanModel\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m model_external = \u001b[43mCmdStanModel\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstan_file\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mbernoulli_external.stan\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mforce_compile\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32m~/Dev/py/cmdstanpy/cmdstanpy/model.py:183\u001b[39m, in \u001b[36mCmdStanModel.__init__\u001b[39m\u001b[34m(self, stan_file, exe_file, force_compile, stanc_options, cpp_options, user_header)\u001b[39m\n\u001b[32m 180\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m path \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._stanc_options[\u001b[33m'\u001b[39m\u001b[33minclude-paths\u001b[39m\u001b[33m'\u001b[39m]:\n\u001b[32m 181\u001b[39m \u001b[38;5;28mself\u001b[39m._stanc_options[\u001b[33m'\u001b[39m\u001b[33minclude-paths\u001b[39m\u001b[33m'\u001b[39m].append(path)\n\u001b[32m--> \u001b[39m\u001b[32m183\u001b[39m \u001b[38;5;28mself\u001b[39m._exe_file = \u001b[43mcompilation\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcompile_stan_file\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 184\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mstan_file\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 185\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_compile\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 186\u001b[39m \u001b[43m \u001b[49m\u001b[43mstanc_options\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_stanc_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 187\u001b[39m \u001b[43m \u001b[49m\u001b[43mcpp_options\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcpp_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 188\u001b[39m \u001b[43m \u001b[49m\u001b[43muser_header\u001b[49m\u001b[43m=\u001b[49m\u001b[43muser_header\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 189\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 191\u001b[39m \u001b[38;5;66;03m# try to detect models w/out parameters, needed for sampler\u001b[39;00m\n\u001b[32m 192\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;129;01mnot\u001b[39;00m cmdstan_version_before(\u001b[32m2\u001b[39m, \u001b[32m27\u001b[39m)) \u001b[38;5;129;01mand\u001b[39;00m cmdstan_version_before(\n\u001b[32m 193\u001b[39m \u001b[32m2\u001b[39m, \u001b[32m36\u001b[39m\n\u001b[32m 194\u001b[39m ):\n", "\u001b[36mFile \u001b[39m\u001b[32m~/Dev/py/cmdstanpy/cmdstanpy/compilation.py:429\u001b[39m, in \u001b[36mcompile_stan_file\u001b[39m\u001b[34m(src, force, stanc_options, cpp_options, user_header)\u001b[39m\n\u001b[32m 422\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[33m'\u001b[39m\u001b[33mPCH\u001b[39m\u001b[33m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m console \u001b[38;5;129;01mor\u001b[39;00m \u001b[33m'\u001b[39m\u001b[33mprecompiled header\u001b[39m\u001b[33m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m console:\n\u001b[32m 423\u001b[39m get_logger().warning(\n\u001b[32m 424\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mCmdStan\u001b[39m\u001b[33m'\u001b[39m\u001b[33ms precompiled header (PCH) files \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 425\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mmay need to be rebuilt.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 426\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mPlease run cmdstanpy.rebuild_cmdstan().\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 427\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mIf the issue persists please open a bug report\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 428\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m429\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 430\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mFailed to compile Stan model \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00msrc\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m. Console:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mconsole\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 431\u001b[39m )\n\u001b[32m 432\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mstr\u001b[39m(exe_target)\n", "\u001b[31mValueError\u001b[39m: Failed to compile Stan model '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan'. Console:\n\n--- Translating Stan model to C++ code ---\nbin/stanc --filename-in-msg=bernoulli_external.stan --o=/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan\nSemantic error in 'bernoulli_external.stan', line 2, column 7 to column 16:\n -------------------------------------------------\n 1: functions {\n 2: real make_odds(real theta);\n ^\n 3: }\n 4: data {\n -------------------------------------------------\n\nFunction 'make_odds' is declared without specifying a definition.\nmake: *** [make/program:66: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp] Error 1\n\nCommand ['make', 'STANCFLAGS+=--filename-in-msg=bernoulli_external.stan', '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external']\n\texited with code '2' No such file or directory\n" ] } ], "source": [ "from cmdstanpy import CmdStanModel\n", "model_external = CmdStanModel(stan_file='bernoulli_external.stan', force_compile=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Even enabling the `--allow-undefined` flag to stanc3 will not allow this model to be compiled quite yet." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [ "raises-exception" ] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "12:25:18 - cmdstanpy - INFO - compiling stan file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan to exe file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n" ] }, { "ename": "ValueError", "evalue": "Failed to compile Stan model '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan'. Console:\nERROR: Missing user header.\nBecause --allow-undefined is set, we need a C++ header file to include.\nWe tried to find the user header at:\n /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/user_header.hpp\n\nYou can also set the USER_HEADER variable to the path of your C++ file.\nmake: *** [make/program:52: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/user_header.hpp] Error 1\n\nCommand ['make', 'STANCFLAGS+=--filename-in-msg=bernoulli_external.stan', 'STANCFLAGS+=--allow-undefined', '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external']\n\texited with code '2' No such file or directory\n", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m model_external = \u001b[43mCmdStanModel\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstan_file\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mbernoulli_external.stan\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mforce_compile\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstanc_options\u001b[49m\u001b[43m=\u001b[49m\u001b[43m{\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mallow-undefined\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m:\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32m~/Dev/py/cmdstanpy/cmdstanpy/model.py:183\u001b[39m, in \u001b[36mCmdStanModel.__init__\u001b[39m\u001b[34m(self, stan_file, exe_file, force_compile, stanc_options, cpp_options, user_header)\u001b[39m\n\u001b[32m 180\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m path \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._stanc_options[\u001b[33m'\u001b[39m\u001b[33minclude-paths\u001b[39m\u001b[33m'\u001b[39m]:\n\u001b[32m 181\u001b[39m \u001b[38;5;28mself\u001b[39m._stanc_options[\u001b[33m'\u001b[39m\u001b[33minclude-paths\u001b[39m\u001b[33m'\u001b[39m].append(path)\n\u001b[32m--> \u001b[39m\u001b[32m183\u001b[39m \u001b[38;5;28mself\u001b[39m._exe_file = \u001b[43mcompilation\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcompile_stan_file\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 184\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mstan_file\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 185\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_compile\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 186\u001b[39m \u001b[43m \u001b[49m\u001b[43mstanc_options\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_stanc_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 187\u001b[39m \u001b[43m \u001b[49m\u001b[43mcpp_options\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcpp_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 188\u001b[39m \u001b[43m \u001b[49m\u001b[43muser_header\u001b[49m\u001b[43m=\u001b[49m\u001b[43muser_header\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 189\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 191\u001b[39m \u001b[38;5;66;03m# try to detect models w/out parameters, needed for sampler\u001b[39;00m\n\u001b[32m 192\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;129;01mnot\u001b[39;00m cmdstan_version_before(\u001b[32m2\u001b[39m, \u001b[32m27\u001b[39m)) \u001b[38;5;129;01mand\u001b[39;00m cmdstan_version_before(\n\u001b[32m 193\u001b[39m \u001b[32m2\u001b[39m, \u001b[32m36\u001b[39m\n\u001b[32m 194\u001b[39m ):\n", "\u001b[36mFile \u001b[39m\u001b[32m~/Dev/py/cmdstanpy/cmdstanpy/compilation.py:429\u001b[39m, in \u001b[36mcompile_stan_file\u001b[39m\u001b[34m(src, force, stanc_options, cpp_options, user_header)\u001b[39m\n\u001b[32m 422\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[33m'\u001b[39m\u001b[33mPCH\u001b[39m\u001b[33m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m console \u001b[38;5;129;01mor\u001b[39;00m \u001b[33m'\u001b[39m\u001b[33mprecompiled header\u001b[39m\u001b[33m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m console:\n\u001b[32m 423\u001b[39m get_logger().warning(\n\u001b[32m 424\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mCmdStan\u001b[39m\u001b[33m'\u001b[39m\u001b[33ms precompiled header (PCH) files \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 425\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mmay need to be rebuilt.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 426\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mPlease run cmdstanpy.rebuild_cmdstan().\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 427\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mIf the issue persists please open a bug report\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 428\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m429\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 430\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mFailed to compile Stan model \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00msrc\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m. Console:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mconsole\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 431\u001b[39m )\n\u001b[32m 432\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mstr\u001b[39m(exe_target)\n", "\u001b[31mValueError\u001b[39m: Failed to compile Stan model '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan'. Console:\nERROR: Missing user header.\nBecause --allow-undefined is set, we need a C++ header file to include.\nWe tried to find the user header at:\n /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/user_header.hpp\n\nYou can also set the USER_HEADER variable to the path of your C++ file.\nmake: *** [make/program:52: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/user_header.hpp] Error 1\n\nCommand ['make', 'STANCFLAGS+=--filename-in-msg=bernoulli_external.stan', 'STANCFLAGS+=--allow-undefined', '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external']\n\texited with code '2' No such file or directory\n" ] } ], "source": [ "model_external = CmdStanModel(stan_file='bernoulli_external.stan', force_compile=True, stanc_options={'allow-undefined':True})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To resolve this, we need to both tell the Stan compiler an undefined function is okay **and** let C++ know what it should be. \n", "\n", "We can provide a definition in a C++ header file by using the `user_header` argument to either the CmdStanModel constructor or the `compile` method. \n", "\n", "This will enables the `allow-undefined` flag automatically." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "12:25:18 - cmdstanpy - INFO - compiling stan file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan to exe file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n", "12:25:34 - cmdstanpy - INFO - compiled model executable: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n" ] } ], "source": [ "model_external = CmdStanModel(stan_file='bernoulli_external.stan', user_header='make_odds.hpp')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can then run this model and inspect the output" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "12:25:34 - cmdstanpy - INFO - CmdStan start processing\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "623a9281ae694435b03929bb08011a69", "version_major": 2, "version_minor": 0 }, "text/plain": [ "chain 1: 0%| | 0/2000 [00:00\n", "\n", "double make_odds(const double& theta, std::ostream *pstream__) {\n", " return theta / (1 - theta);\n", "}\n", "```\n", "\n", "Additional guidance, including on writing functions with known derivatives, can be found in the [CmdStan documentation](https://mc-stan.org/docs/cmdstan-guide/using-external-cpp-code.html)." ] } ], "metadata": { "kernelspec": { "display_name": "stan", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }